package lily.phs.child;

import lily.phs.object.HereTipa;
import lily.phs.object.NewBornChild;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;



import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

/**
 * @author chen
 *该类用于显示“新生儿家庭访视记录表”中前半部分的内容
 */
public class NewChildBornView extends RelativeLayout implements OnFocusChangeListener,OnClickListener{
	Paint paint;
	private int profileid=0;
	private LinearLayout ll1;
	private EditText et_name,et_id,et_birthday,et_perid,et_address,
					 et_father_name,et_father_pro,et_father_tel,et_father_birth,
					 et_mum_name,et_mum_pro,et_mum_tel,et_mum_birth,
					 et_chushengyunzhou,et_mum_disease_other,
					 et_zhuchanjigou,et_chusheng_other,
					 et_jixing_yes,
					 et_disease_other,
					 et_bornweight,et_nowweight,et_born_height,
					 et_milk_value,et_milk_num,
					 et_dabian_num,
					 et_body_temp,et_puls,et_breath_num;
	View vv;
	MyPopupWindow mPopupWindow;
	private Context myContext;
	private RadioButton rb_sex_weizhi,rb_sex_man,rb_sex_women,rb_sex_weishuoming,
				rb_mum_diabetes,rb_mum_gaoxueya,rb_mum_other,
				rb_zhixi_no,rb_zhixi_yes,rb_jixing_no,rb_jixing_yes,
				rb_hearing_pass,rb_hearing_nopass,rb_hearing_weishaicha,rb_hearing_noknow,
				rb_disease_jiadi,rb_disease_bbtnz,rb_disease_other,
				rb_chunmuru,rb_hunhe,rb_rengong,
				rb_outu_no,rb_outu_yes,rb_dabian_huzhuang,rb_dabian_xi;
	
	private CheckBox cb_shunchan,cb_taitouxiyin,cb_chanqian,cb_pougong,cb_shuangduotai,cb_tunwei,cb_other;
	private RadioGroup rg_zhixi,rg_mum_disease,rg_jixing,rg_hearing,rg_disease,rg_feedway,rg_outu,rg_dabian;
	
	HereTipa ht;
	public NewBornChild nbc;
	
	public NewChildBornView(Context context,int pro) {
		super(context);
		myContext=context;
		this.profileid=pro;
		paint=new Paint();
		paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLACK);
        findWeight();
        addToView();
	}
	
	/**
	 * 该函数用于初始化本界面中的所有控件
	 */
	public void findWeight(){
		LayoutInflater factory = LayoutInflater.from(myContext);
        vv = factory.inflate(R.layout.new_child_fam_ask, null);
     
        
        ll1=(LinearLayout)vv.findViewById(R.id.ll);
		et_name=(EditText)vv.findViewById(R.id.et_new_child_name);
		et_name.setInputType(InputType.TYPE_NULL);
		et_id=(EditText)vv.findViewById(R.id.et_new_child_id);
		et_id.setInputType(InputType.TYPE_NULL);
		et_birthday=(EditText)vv.findViewById(R.id.et_newchild_birthday);
		et_birthday.setInputType(InputType.TYPE_NULL);
		et_birthday.setOnClickListener(this);
		et_birthday.setOnFocusChangeListener(this);
		et_perid=(EditText)vv.findViewById(R.id.et_newchild_perid);
		et_address=(EditText)vv.findViewById(R.id.et_newchild_address);
		rb_sex_weizhi=(RadioButton)vv.findViewById(R.id.rb_new_child_sex_weizhi);
		rb_sex_man=(RadioButton)vv.findViewById(R.id.rb_new_child_sex_man);
		rb_sex_women=(RadioButton)vv.findViewById(R.id.rb_new_child_sex_women);
		rb_sex_weishuoming=(RadioButton)vv.findViewById(R.id.rb_new_child_sex_weishuoming);
		rb_sex_weizhi.setOnClickListener(this);
		rb_sex_man.setOnClickListener(this);
		rb_sex_women.setOnClickListener(this);
		rb_sex_weishuoming.setOnClickListener(this);
		et_father_name=(EditText)vv.findViewById(R.id.et_newchild_fath_name);
		et_father_pro=(EditText)vv.findViewById(R.id.et_newchild_fath_pro);
		et_father_tel=(EditText)vv.findViewById(R.id.et_newchild_fath_tel);
		et_father_birth=(EditText)vv.findViewById(R.id.et_newchild_father_birth);
		et_father_birth.setInputType(InputType.TYPE_NULL);
		et_father_birth.setOnClickListener(this);
		et_father_birth.setOnFocusChangeListener(this);
		et_mum_name=(EditText)vv.findViewById(R.id.et_newchild_mum_name);
		et_mum_pro=(EditText)vv.findViewById(R.id.et_newchild_mum_pro);
		et_mum_tel=(EditText)vv.findViewById(R.id.et_newchild_mum_tel);
		et_mum_birth=(EditText)vv.findViewById(R.id.et_newchild_mum_birth);
		et_mum_birth.setInputType(InputType.TYPE_NULL);
		et_mum_birth.setOnClickListener(this);
		et_mum_birth.setOnFocusChangeListener(this);
		et_chushengyunzhou=(EditText)vv.findViewById(R.id.et_newchild_chushengyunzhou);
		rg_mum_disease=(RadioGroup)vv.findViewById(R.id.rg_newchild_mumdisease);
		rb_mum_diabetes=(RadioButton)vv.findViewById(R.id.rb_newchild_mumdisease_diabetes);
		rb_mum_gaoxueya=(RadioButton)vv.findViewById(R.id.rb_newchild_mumdisease_gaoxueya);
		rb_mum_other=(RadioButton)vv.findViewById(R.id.rb_newchild_mumdisease_other);
		et_mum_disease_other=(EditText)vv.findViewById(R.id.et_newchild_mumdisease_other);
		et_zhuchanjigou=(EditText)vv.findViewById(R.id.et_newchild_zhuchanjigou);
		cb_shunchan=(CheckBox)vv.findViewById(R.id.cb_newchild_shunchan);
		cb_tunwei=(CheckBox)vv.findViewById(R.id.cb_newchild_tunwei);
		cb_taitouxiyin=(CheckBox)vv.findViewById(R.id.cb_newchild_taitouxiyin);
		cb_chanqian=(CheckBox)vv.findViewById(R.id.cb_newchild_chanqian);
		cb_pougong=(CheckBox)vv.findViewById(R.id.cb_newchild_pougong);
		cb_shuangduotai=(CheckBox)vv.findViewById(R.id.cb_newchild_shuangduotai);
		cb_other=(CheckBox)vv.findViewById(R.id.cb_newchild_chusheng_other);
		cb_shunchan=(CheckBox)vv.findViewById(R.id.cb_newchild_shunchan);
		et_chusheng_other=(EditText)vv.findViewById(R.id.et_newchild_chusheng_other);
		rg_zhixi=(RadioGroup)vv.findViewById(R.id.rg_newchild_zhixi);
		rb_zhixi_no=(RadioButton)vv.findViewById(R.id.rb_newchild_zhixi_no);
		rb_zhixi_no.setOnClickListener(this);
		rb_zhixi_yes=(RadioButton)vv.findViewById(R.id.rb_newchild_zhixi_yes);
		rg_jixing=(RadioGroup)vv.findViewById(R.id.rg_newchild_jixing);
		rb_jixing_no=(RadioButton)vv.findViewById(R.id.rb_newchild_jixing_no);
		rb_jixing_yes=(RadioButton)vv.findViewById(R.id.rb_newchild_jixing_yes);
		et_jixing_yes=(EditText)vv.findViewById(R.id.et_newchild_jixing_yes);
		rg_hearing=(RadioGroup)vv.findViewById(R.id.rg_newchild_hearing);
		rb_hearing_pass=(RadioButton)vv.findViewById(R.id.rb_newchild_hearing_pass);
		rb_hearing_nopass=(RadioButton)vv.findViewById(R.id.rb_newchild_hearing_nopass);
		rb_hearing_weishaicha=(RadioButton)vv.findViewById(R.id.rb_newchild_hearing_weishaicha);
		rb_hearing_noknow=(RadioButton)vv.findViewById(R.id.rb_newchild_hearing_noknow);
		rg_disease=(RadioGroup)vv.findViewById(R.id.rg_newchild_disease);
		rb_disease_jiadi=(RadioButton)vv.findViewById(R.id.rb_newchild_disease_jiadi);
		rb_disease_bbtnz=(RadioButton)vv.findViewById(R.id.rb_newchild_disease_bbtnz);
		rb_disease_other=(RadioButton)vv.findViewById(R.id.rb_newchild_disease_other);
		et_disease_other=(EditText)vv.findViewById(R.id.et_newchild_disease_other);
		et_bornweight=(EditText)vv.findViewById(R.id.et_newchild_bornweight);
		et_nowweight=(EditText)vv.findViewById(R.id.et_newchild_nowweight);
		et_born_height=(EditText)vv.findViewById(R.id.et_newchild_born_height);
		rg_feedway=(RadioGroup)vv.findViewById(R.id.rg_newchild_feedway);
		rb_chunmuru=(RadioButton)vv.findViewById(R.id.rb_newchild_chunmuru);
		rb_hunhe=(RadioButton)vv.findViewById(R.id.rb_newchild_hunhe);
		rb_rengong=(RadioButton)vv.findViewById(R.id.rb_newchild_rengong);
		et_milk_value=(EditText)vv.findViewById(R.id.et_newchild_milk_value);
		et_milk_num=(EditText)vv.findViewById(R.id.et_newchild_milk_num);
		rg_outu=(RadioGroup)vv.findViewById(R.id.rg_newchild_outu);
		rb_outu_no=(RadioButton)vv.findViewById(R.id.rb_newchild_outu_no);
		rb_outu_yes=(RadioButton)vv.findViewById(R.id.rb_newchild_outu_yes);
		rg_dabian=(RadioGroup)vv.findViewById(R.id.rg_newchild_dabian);
		rb_dabian_huzhuang=(RadioButton)vv.findViewById(R.id.rb_newchild_dabian_huzhuang);
		rb_dabian_xi=(RadioButton)vv.findViewById(R.id.rb_newchild_dabian_xi);
		et_dabian_num=(EditText)vv.findViewById(R.id.et_newchild_dabian_num);
		et_body_temp=(EditText)vv.findViewById(R.id.et_newchild_body_temp);
		et_puls=(EditText)vv.findViewById(R.id.et_newchild_puls);
		et_breath_num=(EditText)vv.findViewById(R.id.et_newchild_breath_num);
		ht=new HereTipa(myContext);
		ht.selectNameAndCode(profileid);
		nbc=new NewBornChild(myContext);
		nbc.selectNewBornChild(profileid);
		/*LayoutParams lp=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
		
		this.addView(vv,lp);
		
		/*MyView mv=new MyView(myContext);
		this.addView(mv,lp);*/
		//selectData();
	}
	
	public void addToView(){
		LayoutParams lp=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
		this.addView(vv,lp);
		MyView mv=new MyView(myContext);
		this.addView(mv,lp);
	}
	
	/**
	 * 该函数用于重新获取数据库中profileid所对应的该表 的记录
	 */
	public void selectData(){
		ht.selectNameAndCode(profileid);
		nbc.selectNewBornChild(profileid);
	}
	
	/**
	 * 该函数用于通过数据库中的记录初始化各个控件的值
	 */
	public void initView(){
		
		if(ht.getHeti_name()!=null){
			et_name.setText(ht.getHeti_name());
		}
		if(ht.getHeti_here_id()!=null){
			et_id.setText(ht.getHeti_here_id());
		}
		
		if(nbc.getBoch_sex()>=0){
			switch(nbc.getBoch_sex()){
			case 0:
				Log.e("TEST1","rb_sex_weizhi.isChecked()"+rb_sex_weizhi.isChecked());
				rb_sex_weizhi.setChecked(true);
				Log.e("TEST1","rb_sex_weizhi.isChecked()"+rb_sex_weizhi.isChecked());
				break;
			case 1:
				rb_sex_man.setChecked(true);
				break;
			case 2:
				rb_sex_women.setChecked(true);
				break;
			case 9:
				rb_sex_weishuoming.setChecked(true);
				break;
				default:
					break;
			}
		}
		et_birthday.setText(nbc.getBoch_birthdar());
		et_perid.setText(nbc.getBoch_perid());
		et_address.setText(nbc.getBoch_fam_addr());
		et_father_name.setText(nbc.getBoch_fath_name());
		et_father_pro.setText(nbc.getBoch_fath_pro());
		et_father_tel.setText(nbc.getBoch_fath_tel());
		et_father_birth.setText(nbc.getBoch_fath_birth());
		et_mum_name.setText(nbc.getBoch_mum_name());
		et_mum_pro.setText(nbc.getBoch_mum_pro());
		et_mum_tel.setText(nbc.getBoch_mum_tel());
		et_mum_birth.setText(nbc.getBoch_mum_birth());
		if(nbc.getBoch_gw()>0){
			et_chushengyunzhou.setText(nbc.getBoch_gw()+"");
		}
		if(nbc.getBoch_mum_disease()>0){
			switch(nbc.getBoch_mum_disease()){
			case 1:
				rg_mum_disease.check(0);
				rb_mum_diabetes.setChecked(true);
				break;
			case 2:
				rg_mum_disease.check(1);
				rb_mum_gaoxueya.setChecked(true);
				break;
			case 3:
				rg_mum_disease.check(2);
				rb_mum_other.setChecked(true);
				break;
				default:
					break;
			}
		}
		et_mum_disease_other.setText(nbc.getBoch_mum_disease_other());
		et_zhuchanjigou.setText(nbc.getBoch_part_inst());
		String strs[]=null;
		if(nbc.getBoch_born_inst()!=null&&nbc.getBoch_born_inst().length()>0){
			strs=nbc.getBoch_born_inst().split(",");
		}
		if(strs!=null){
			for(int i=0;i<strs.length;i++){
				int j=Integer.parseInt(strs[i]);
				switch(j){
				case 1:
					cb_shunchan.setChecked(true);
					break;
				case 2:
					cb_taitouxiyin.setChecked(true);
					break;
				case 3:
					cb_chanqian.setChecked(true);
					break;
				case 4:
					cb_pougong.setChecked(true);
					break;
				case 5:
					cb_shuangduotai.setChecked(true);
					break;
				case 6:
					cb_tunwei.setChecked(true);
					break;
				case 7:
					cb_other.setChecked(true);
					et_chusheng_other.setText(nbc.getBoch_born_inst_other());
					break;
					default:
						break;
				}
			}
		}
		
		
		if(nbc.getBoch_smother()>0){
			switch(nbc.getBoch_smother()){
			case 1:
				Log.e("TEST1","rb_zhixi_no.isChecked()"+rb_zhixi_no.isChecked());
				rg_zhixi.check(0);
				rb_zhixi_no.setChecked(true);
				System.out.println();
				Log.e("TEST2","rb_zhixi_no.isChecked()"+rb_zhixi_no.isChecked());
				break;
			case 2:
				rg_zhixi.check(1);
				rb_zhixi_yes.setChecked(true);
				break;
			}
		}
		if(nbc.getBoch_abnormal()==1){
			rg_jixing.check(0);
			rb_jixing_no.setChecked(true);
		}
		else if(nbc.getBoch_abnormal()==2){
			rg_jixing.check(1);
			rb_jixing_yes.setChecked(true);
			et_jixing_yes.setText(nbc.getBoch_abnormal_info());
		}
		
		if(nbc.getBoch_hearing()>0){
			switch(nbc.getBoch_hearing()){
			case 1:
				rg_hearing.check(0);
				rb_hearing_pass.setChecked(true);
				break;
			case 2:
				rg_hearing.check(1);
				rb_hearing_nopass.setChecked(true);
				break;
			case 3:
				rg_hearing.check(2);
				rb_hearing_weishaicha.setChecked(true);
				break;
			case 4:
				rg_hearing.check(3);
				rb_hearing_noknow.setChecked(true);
				break;
				default:
					break;
			}
		}
		if(nbc.getBoch_disease()>0){
			switch(nbc.getBoch_disease()){
			case 1:
				rg_disease.check(0);
				rb_disease_jiadi.setChecked(true);
				break;
			case 2:
				rg_disease.check(1);
				rb_disease_bbtnz.setChecked(true);
				break;
			case 3:
				rg_disease.check(2);
				rb_disease_other.setChecked(true);
				et_disease_other.setText(nbc.getBoch_disease_other());
				break;
				default:
					break;
			}
		}
		
		if(nbc.getBoch_born_weight()>0){
			et_bornweight.setText(""+nbc.getBoch_born_weight());
		}
		if(nbc.getBoch_now_weight()>0){
			et_nowweight.setText(""+nbc.getBoch_now_weight());
		}
		if(nbc.getBoch_heig_value()>0){
			et_born_height.setText(""+nbc.getBoch_heig_value());
		}
		if(nbc.getBoch_feed_way()>0){
			switch(nbc.getBoch_feed_way()){
			case 1:
				rg_feedway.check(0);
				rb_chunmuru.setChecked(true);
				break;
			case 2:
				rg_feedway.check(1);
				rb_hunhe.setChecked(true);
				break;
			case 3:
				rg_feedway.check(2);
				rb_rengong.setChecked(true);
				break;
				default:
					break;
			}
		}
		if(nbc.getBoch_feed_milk()>0){
			et_milk_value.setText(""+nbc.getBoch_feed_milk());
		}
		if(nbc.getBoch_feed_milk_num()>0){
			et_milk_num.setText(""+nbc.getBoch_feed_milk_num());
		}
		if(nbc.getBoch_vomit()>0){
			switch(nbc.getBoch_vomit()){
			case 1:
				rg_outu.check(0);
				rb_outu_no.setChecked(true);
				break;
			case 2:
				rg_outu.check(1);
				rb_outu_yes.setChecked(true);
				break;
				default:
					break;
			}
		}
		if(nbc.getBoch_faeces()>0){
			switch(nbc.getBoch_faeces()){
			case 1:
				rg_dabian.check(0);
				rb_dabian_huzhuang.setChecked(true);
				break;
			case 2:
				rg_dabian.check(1);
				rb_dabian_xi.setChecked(true);
				break;
				default:
					break;
			}
		}
		if(nbc.getBoch_faeces_num()>0){
			et_dabian_num.setText(nbc.getBoch_faeces_num()+"");
		}
		if(nbc.getBoch_body_temp()>0){
			et_body_temp.setText(nbc.getBoch_body_temp()+"");
		}
		if(nbc.getBoch_pulse()>0){
			et_puls.setText(nbc.getBoch_pulse()+"");
		}
		if(nbc.getBoch_breath()>0){
			et_breath_num.setText(nbc.getBoch_breath()+"");
		}
	}
	
	/**
	 * @return若保存成功返回true，若保存失败返回false
	 * 该函数用于将本界面中控件的值保存到数据库中
	 */
	public boolean saveView(){
		if(et_chushengyunzhou.getText().toString().replaceAll("\\s", "").length()>8||
				et_chushengyunzhou.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_chushengyunzhou.setError("输入的数值超过范围");
			return false;
		}
		if(et_bornweight.getText().toString().replaceAll("\\s", "").length()>10||
				et_bornweight.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_bornweight.setError("输入的数值超过范围");
			return false;
		}
		if(et_nowweight.getText().toString().replaceAll("\\s", "").length()>10||
				et_nowweight.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_nowweight.setError("输入的数值超过范围");
			return false;
		}
		if(et_born_height.getText().toString().replaceAll("\\s", "").length()>10||
				et_born_height.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_born_height.setError("输入的数值超过范围");
			return false;
		}
		if(et_milk_value.getText().toString().replaceAll("\\s", "").length()>10||
				et_milk_value.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_milk_value.setError("输入的数值超过范围");
			return false;
		}
		if(et_milk_num.getText().toString().replaceAll("\\s", "").length()>8||
				et_milk_num.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_milk_num.setError("输入的数值超过范围");
			return false;
		}
		if(et_dabian_num.getText().toString().replaceAll("\\s", "").length()>8||
				et_dabian_num.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_dabian_num.setError("输入的数值超过范围");
			return false;
		}
		if(et_body_temp.getText().toString().replaceAll("\\s", "").length()>10||
				et_body_temp.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_body_temp.setError("输入的数值超过范围");
			return false;
		}
		if(et_puls.getText().toString().replaceAll("\\s", "").length()>8||
				et_puls.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_puls.setError("输入的数值超过范围");
			return false;
		}
		if(et_breath_num.getText().toString().replaceAll("\\s", "").length()>8||
				et_breath_num.getText().toString().replaceAll("\\s", "").startsWith("-")){
			et_breath_num.setError("输入的数值超过范围");
			return false;
		}
		NewBornChild nbc=new NewBornChild(myContext);
		nbc.selectNewBornChild(profileid);
		if(rb_sex_weizhi.isChecked()){
			nbc.setBoch_sex(0);
		}
		else if(rb_sex_man.isChecked()){
			nbc.setBoch_sex(1);
		}
		else if(rb_sex_women.isChecked()){
			nbc.setBoch_sex(2);
		}
		else if(rb_sex_weishuoming.isChecked()){
			nbc.setBoch_sex(9);
		}
		nbc.setBoch_birthdar(et_birthday.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_perid(et_perid.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_fam_addr(et_address.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_fath_name(et_father_name.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_fath_pro(et_father_pro.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_fath_tel(et_father_tel.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_fath_birth(et_father_birth.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_mum_name(et_mum_name.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_mum_pro(et_mum_pro.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_mum_tel(et_mum_tel.getText().toString().replaceAll("\\s", ""));
		nbc.setBoch_mum_birth(et_mum_birth.getText().toString().replaceAll("\\s", ""));
		if(et_chushengyunzhou.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_gw(Integer.parseInt(et_chushengyunzhou.getText().toString().replaceAll("\\s", "")));
		}
		if(rb_mum_diabetes.isChecked()){
			nbc.setBoch_mum_disease(1);
		}
		else if(rb_mum_gaoxueya.isChecked()){
			nbc.setBoch_mum_disease(2);
		}
		else if(rb_mum_other.isChecked()){
			nbc.setBoch_mum_disease(3);
			nbc.setBoch_mum_disease_other(et_mum_disease_other.getText().toString().replaceAll("\\s", ""));
		}
		nbc.setBoch_part_inst(et_zhuchanjigou.getText().toString().replaceAll("\\s", ""));
		String str="";
		if(cb_shunchan.isChecked()){
			str+="1,";
		}
		if(cb_taitouxiyin.isChecked()){
			str+="2,";
		}
		if(cb_chanqian.isChecked()){
			str+="3,";
		}
		if(cb_pougong.isChecked()){
			str+="4,";
		}
		if(cb_shuangduotai.isChecked()){
			str+="5,";
		}
		if(cb_tunwei.isChecked()){
			str+="6,";
		}
		if(cb_other.isChecked()){
			str+="7";
			nbc.setBoch_born_inst_other(et_chusheng_other.getText().toString().replaceAll("\\s", ""));
		}
		nbc.setBoch_born_inst(str);
		if(rb_zhixi_no.isChecked()){
			nbc.setBoch_smother(1);
		}
		else if(rb_zhixi_yes.isChecked()){
			nbc.setBoch_smother(2);
		}
		if(rb_jixing_no.isChecked()){
			nbc.setBoch_abnormal(1);
		}
		else if(rb_jixing_yes.isChecked()){
			nbc.setBoch_abnormal(2);
			nbc.setBoch_abnormal_info(et_jixing_yes.getText().toString().replaceAll("\\s", ""));
		}
		if(rb_hearing_pass.isChecked()){
			nbc.setBoch_hearing(1);
		}
		else if(rb_hearing_nopass.isChecked()){
			nbc.setBoch_hearing(2);
		}
		else if(rb_hearing_weishaicha.isChecked()){
			nbc.setBoch_hearing(3);
		}
		else if(rb_hearing_noknow.isChecked()){
			nbc.setBoch_hearing(4);
		}
		if(rb_disease_jiadi.isChecked()){
			nbc.setBoch_disease(1);
		}
		else if(rb_disease_bbtnz.isChecked()){
			nbc.setBoch_disease(2);
		}
		else if(rb_disease_other.isChecked()){
			nbc.setBoch_disease(3);
			nbc.setBoch_disease_other(et_disease_other.getText().toString().replaceAll("\\s", ""));
		}
		if(et_bornweight.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_born_weight(Float.parseFloat(et_bornweight.getText().toString().replaceAll("\\s", "")));
		}
		if(et_nowweight.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_now_weight(Float.parseFloat(et_nowweight.getText().toString().replaceAll("\\s", "")));
		}
		if(et_born_height.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_heig_value(Float.parseFloat(et_born_height.getText().toString().replaceAll("\\s", "")));
		}
		if(rb_chunmuru.isChecked()){
			nbc.setBoch_feed_way(1);
		}
		else if(rb_hunhe.isChecked()){
			nbc.setBoch_feed_way(2);
		}
		else if(rb_rengong.isChecked()){
			nbc.setBoch_feed_way(3);
		}
		if(et_milk_value.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_feed_milk(Float.parseFloat(et_milk_value.getText().toString().replaceAll("\\s", "")));
		}
		if(et_milk_num.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_feed_milk_num(Integer.parseInt(et_milk_num.getText().toString().replaceAll("\\s", "")));
		}
		if(rb_outu_no.isChecked()){
			nbc.setBoch_vomit(1);
		}
		else if(rb_outu_yes.isChecked()){
			nbc.setBoch_vomit(2);
		}
		if(rb_dabian_huzhuang.isChecked()){
			nbc.setBoch_faeces(1);
		}
		else if(rb_dabian_xi.isChecked()){
			nbc.setBoch_faeces(2);
		}
		if(et_dabian_num.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_faeces_num(Integer.parseInt(et_dabian_num.getText().toString().replaceAll("\\s", "")));
		}
		if(et_body_temp.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_body_temp(Float.parseFloat(et_body_temp.getText().toString().replaceAll("\\s", "")));
		}
		if(et_puls.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_pulse(Integer.parseInt(et_puls.getText().toString().replaceAll("\\s", "")));
		}
		if(et_breath_num.getText().toString().replaceAll("\\s", "").length()>0){
			nbc.setBoch_breath(Integer.parseInt(et_breath_num.getText().toString().replaceAll("\\s", "")));
		}
		nbc.updateNewBornChild(profileid);
		return true;
	}
	
	class MyView extends View {
    	Paint paint;
    	
		public MyView(Context context) {
			super(context);
			paint=new Paint();
			paint.setStyle(Paint.Style.STROKE);
            paint.setColor(Color.BLACK);
		}
		
		@Override
		public void onDraw(Canvas c){
	        int top=ll1.getTop();
	        int left=ll1.getLeft()-15;
	        int right=ll1.getRight()+15;
	        int bottom=ll1.getBottom();
	        int y=0;//sv.getScrollY();
	        int height=rb_sex_weizhi.getHeight();
	        int height2=et_name.getHeight();
	        top=top-y;
	        bottom=bottom-y;
	        
	        c.drawLine(left, top+170, right, top+170, paint);
	        c.drawLine(left, top+190+40+2*height, right, top+190+40+2*height, paint);
	        c.drawLine(left, top+190+40*2+2*height+1*height2, right, top+190+40*2+2*height+1*height2, paint);
	        c.drawLine(left, top+190+40*3+2*height+2*height2, right, top+190+40*3+2*height+2*height2, paint);
	        c.drawLine(left, top+190+40*4+2*height+3*height2, right, top+190+40*4+2*height+3*height2, paint);
	        c.drawLine(left, top+190+40*5+2*height+4*height2, right, top+190+40*5+2*height+4*height2, paint);
	        c.drawLine(left, top+210+40*6+4*height+4*height2, right, top+210+40*6+4*height+4*height2, paint);
	        c.drawLine(left, top+210+40*7+4*height+5*height2, right, top+210+40*7+4*height+5*height2, paint);
	        c.drawLine(left, top+210+40*8+5*height+5*height2, right, top+210+40*8+5*height+5*height2, paint);
	        c.drawLine(left, top+210+40*9+5*height+6*height2, right, top+210+40*9+5*height+6*height2, paint);
	        c.drawLine(left, top+210+40*10+5*height+7*height2, right, top+210+40*10+5*height+7*height2, paint);
	        c.drawLine(left, top+210+40*11+5*height+8*height2, right, top+210+40*11+5*height+8*height2, paint);
	        c.drawLine(left, top+210+40*12+5*height+9*height2, right, top+210+40*12+5*height+9*height2, paint);
	        c.drawLine(left, top+210+40*13+5*height+10*height2, right, top+210+40*13+5*height+10*height2, paint);
	        
	        c.drawLine(left, top+170, left, top+210+40*13+5*height+10*height2, paint);
	        c.drawLine(right, top+170, right, top+210+40*13+5*height+10*height2, paint);
	        
	        c.drawLine(left+365, top+170, left+365, top+190+40*2+2*height+1*height2, paint);
	        
	        c.drawLine(left+75, top+190+40*2+2*height+1*height2, left+75, top+190+40*4+2*height+3*height2, paint);
	        
	        c.drawLine(left+215, top+190+40*4+2*height+3*height2, left+215, top+210+40*6+4*height+4*height2, paint);
	        
	        c.drawLine(left+365, top+210+40*6+4*height+4*height2, left+365, top+210+40*7+4*height+5*height2, paint);
	        
	        c.drawLine(left+315, top+210+40*9+5*height+6*height2, left+315, top+210+40*13+5*height+10*height2, paint);
	        c.drawLine(left+515, top+210+40*9+5*height+6*height2, left+515, top+210+40*13+5*height+10*height2, paint);
		}
    	
    }
	

	@Override
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_birthday){
			mPopupWindow = new MyPopupWindow(myContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_birthday), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_birthday.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==rb_sex_weizhi){
			System.out.println("weizhi click");
			rb_sex_weizhi.setChecked(true);
			
			rb_sex_man.setChecked(false);
			rb_sex_women.setChecked(false);
			rb_sex_weishuoming.setChecked(false);
		}
		else if(v==rb_sex_man){
			rb_sex_weizhi.setChecked(false);
			rb_sex_man.setChecked(true);
			rb_sex_women.setChecked(false);
			rb_sex_weishuoming.setChecked(false);
		}
		else if(v==rb_sex_women){
			rb_sex_weizhi.setChecked(false);
			rb_sex_man.setChecked(false);
			rb_sex_women.setChecked(true);
			rb_sex_weishuoming.setChecked(false);
		}
		else if(v==rb_sex_weishuoming){
			rb_sex_weizhi.setChecked(false);
			rb_sex_man.setChecked(false);
			rb_sex_women.setChecked(false);
			rb_sex_weishuoming.setChecked(true);
		}
		else if(v==rb_zhixi_no){
			rb_zhixi_no.setChecked(true);
		}
		else if(v==et_father_birth){
			mPopupWindow = new MyPopupWindow(myContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_father_birth), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_father_birth.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_mum_birth){
			mPopupWindow = new MyPopupWindow(myContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_mum_birth), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_mum_birth.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(v==et_birthday&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_birthday), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_birthday.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_father_birth&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_father_birth), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_father_birth.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_mum_birth&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.et_newchild_mum_birth), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_mum_birth.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
	}	
}
